
#pragma once

#include <ConnectionBroker/Packet.h>
#include <ConnectionBroker/clientconnection/ClientConnection.h>
#include <vector>
#include <boost/asio.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp>

namespace ConnectionBroker
{
   class LongPollServer;
   class LongPollClientConnection : public ClientConnection,
                                    public boost::enable_shared_from_this<LongPollClientConnection>
   {
      protected: //Member variables
      boost::asio::deadline_timer mTimer;
      std::vector<ConnectionBroker::Packet> mMessages;
      ConnectionBroker::LongPollServer* mServer;
      int mId;
      std::string mPass;
      boost::asio::io_service& mIoService;
      
      public: //Constructor, destructor
      LongPollClientConnection(ConnectionBroker::LongPollServer* pServer, boost::asio::io_service& pIoService, const int id, const std::string& pass);
      virtual ~LongPollClientConnection();


      public: //Getters
      const int id() const { return mId; }
      const std::string& pass() const { return mPass; }

      public: //Interface
      const std::vector<ConnectionBroker::Packet>& getMessages() const { return mMessages; }
      void reset();
      void timeout(const boost::system::error_code& pError);
      virtual void write(const ConnectionBroker::Packet& pPacket);

      protected: //Utilities
      void doWrite(const ConnectionBroker::Packet& pPacket);

   }; 

   typedef boost::shared_ptr<LongPollClientConnection> LongPollClientConnectionPtr;
}

